# include <stdio.h>
# include <string.h>
# include "Header.h"
# include "DirectoryOps.h"

void makeDir(char *dirPath, char *dirName, struct VFS *header) {
	int i;
	validateDirPath(dirPath, dirName);
	strcat(dirPath, dirName);
	
	for (i = 0; i < MAX_FD_SIZE; i++) {
		if(header -> freeList[i] == 0) {
			copyString(header -> fd[i].filePath, dirPath);
			header -> freeList[i] = 1;
			break;
		}
	}
}

void validateDirPath (char *dirPath, char *dirName) {
	int i = 0;
	while (dirPath[i])
		i++;
	if (dirPath [i - 1] == '/' && dirName[0] == '/')
		dirPath[i - 1] = '\0';
	else if (dirPath [i - 1] != '/' && dirName[0] != '/') {
		dirPath[i++] = '/';
		dirPath[i] = '\0';
	}
}
